
<template>
  <div>
    <el-table
      ref="singleTable"
      :data="tableData"
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column type="index" width="60"></el-table-column>
      <el-table-column property="name" label="姓名" >
      </el-table-column>
       <el-table-column
        property="icon"
        label="頭像"
        
      ></el-table-column>
      <el-table-column
        property="cardId"
        label="身份证号"
        
      ></el-table-column>
      <el-table-column
        property="age"
        label="年龄"
        
      ></el-table-column>
      <el-table-column
        property="gender"
        label="性别"
        
      ></el-table-column>
       <el-table-column
        property="address"
        label="地址"
        
      ></el-table-column>
      <el-table-column
        property="lockd"
        label="是否锁定"
        
      ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleAdd(scope.$index, scope.row)"
            >添加</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <span class="demonstration"></span>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.pageNum"
        :page-size="pageInfo.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="pageInfo.pageTotal"
      ></el-pagination>
    </div>
  
  </div>
</template>
<script>

export default {
  data() {
    return {
      tableData: [],
      dialogFormVisible: false,
      formLabelWidth: "120px",
      pageInfo: {
        pageNum: 1,
        pageSize: 2,
        pageTotal: 0,
      },
    };
  },
  methods: {
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.$axios({
        method: "get",
        url: this.$server + "/api/customer/listnoemp/" + val,
      }).then((r) => {
        this.tableData = r.data.data.list;
      });
    },

    handleAdd(index, row) {
      console.log(row.id);
    this.$axios({
      method: "post",
      url: this.$server+"/api/customer/add",
       
       data:{
           userId:row.id
       }
    }).then((r) => {
      if (r.data.code == 200) {
        this.tableData = r.data.data;
        this.$alert("添加成功!");
      } else if (r.data.code == 500) {
        console.log(r.data.msg);
      } else {
        console.log(r.data.msg);
        alert(r.data.msg);
      }
    });
  }
  },
  created: function () {
    this.$axios({
      method: "get",
      url: this.$server + "/api/customer/listnoemp/" + this.pageInfo.pageNum,
    }).then((r) => {
        console.log(r)
      if (r.data.code == 200) {
        this.tableData = r.data.data.list;
        this.pageInfo.pageTotal=r.data.data.total
      }
    });
  },

  computed: {},
};
</script>